package cn.kduck.code.generate.json;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AiFunctionToolRequest {

    private String type = "function";
    private Function function;

    public AiFunctionToolRequest(String name, String description) {
        this.function = new Function(name,description);
    }

    public String getType() {
        return type;
    }

    public Function getFunction() {
        return function;
    }

    public void setFunction(Function function) {
        this.function = function;
    }

    public static class Function {
        private String name;
        private String description;
        private Parameters parameters = new Parameters();

        public Function(String name, String description) {
            this.name = name;
            this.description = description;
        }

        public void addParameter(String name, String description) {
            addParameter(name, description,true);
        }

        public void addParameter(String name, String description,boolean required) {
            this.parameters.properties.put(name, new Property(description));
            if(required){
                this.parameters.required.add(name);
            }
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }

        public Parameters getParameters() {
            return parameters;
        }

        public void setParameters(Parameters parameters) {
            this.parameters = parameters;
        }
    }

    public static class Parameters {
        private String type;
        private Map<String, Property> properties = new HashMap<>();
        private List<String> required = new ArrayList<>();

        public Parameters() {
            this.type = "object";
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public Map<String, Property> getProperties() {
            return properties;
        }

        public void setProperties(Map<String, Property> properties) {
            this.properties = properties;
        }

        public List<String> getRequired() {
            return required;
        }

        public void setRequired(List<String> required) {
            this.required = required;
        }
    }

    public static class Property {
        private String type;
        private String description;

        public Property(String description) {
            this.type = "object";
            this.description = description;
        }
        public Property(String type, String description) {
            this.type = type;
            this.description = description;
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }
    }
}
